package com.mmlc.meimei.lichengkongjian.Adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.mmlc.businessutils.OrderListUtils;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.meimei.lichengkongjian.been.ListItemBeanNew;
import com.mmlc.meimei.lichengkongjian.been.OrderButtonBean;
import com.mmlc.meimei.lichengkongjian.customview.MuchButtonGroup;
import com.mmlc.meimei.lichengkongjian.customview.MuchOrderItemGroup;
import com.mmlc.meimei.lichengkongjian.mine.ActivityOrderDetail;


public class OrderDetailAdapter extends MyBaseAdapter{

    ListItemBeanNew bean;
    ActivityOrderDetail activity;
    public OrderDetailAdapter(ListItemBeanNew bean, ActivityOrderDetail activity){
        this.bean = bean;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return bean.itemBeenList.size();
    }

    @Override
    public Object getItem(int i) {
        return bean.itemBeenList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View view, ViewGroup viewGroup) {
        Log.e("Test","detail-position"+position);
        final ListItemBeanNew.ItemBean itemBean = bean.itemBeenList.get(position);
        if(view == null){
          //  view = App.layoutInflater.inflate( R.layout.adapter_order_much2,viewGroup,false);
            view = View.inflate( activity, R.layout.adapter_order_much2,null);
        }

        MuchOrderItemGroup itemGroup = (MuchOrderItemGroup)view.findViewById(R.id.mg_itemGroup);

        MuchButtonGroup mg_buttonGroup = itemGroup.addDetailItemClicked(itemBean,bean.type);

        mg_buttonGroup.addButton(itemBean.inButtonType);
        mg_buttonGroup.setMuchButtonClickedListener(new MuchButtonGroup.MuchButtonClickedListener() {
            @Override
            public void clicked(View v, int type) {
                OrderListUtils d = new OrderListUtils();
                d.doSomething(getOrderButtonBean(v,type));
                d.setUpdateUI(new OrderListUtils.UpdateUI() {
                    @Override
                    public void updateUI(int position, int type) {
                        switch(type){
                            case OrderListUtils.UpdateUI.REFRESH:
                                activity.processUI();
                                break;
                        }
                    }
                });
            }

            private OrderButtonBean getOrderButtonBean(View v, int type) {
                OrderButtonBean buttonBean = new OrderButtonBean();
                buttonBean.rootView = activity.rootView;
                buttonBean.activity = activity;
                buttonBean.itemPositon = position;
                buttonBean.orderId = bean.orderNumber;
                buttonBean.goodsId = itemBean.id;
                buttonBean.buttonType = type;
                buttonBean.payType = bean.payCode;
                buttonBean.buttonView = v;
                buttonBean.from = OrderButtonBean.IGNORE;
                buttonBean.tip = bean.tip ;
                return buttonBean;
            }
        });

        return view;
    }

    @Override
    public void deleteItem(int position) {

    }
}

